<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!--历史记录页面，用列表展示-->
<input type="hidden" value="${order.id}" id="orderId">
<%--<div class="dggui-tab-item dggui-show">--%>
    <label>备注节点：</label>
    <select class="dggui-select" id="note_type">
        <option value="">请选择</option>
        <c:forEach var="remarksnode" items="${productNodes}">
            <option value="${remarksnode.id}">${remarksnode.name}</option>
        </c:forEach>
    </select>
    <div class="textarea-warp">
        <textarea class="dggui-textarea" id="note_detail" placeholder="添加备注信息" rows="4" maxlength="500"></textarea>
    </div>
    <c:if test="${empty detailType}">
        <button class="dggui-btn" onclick="saveremarkByDetail()">保存</button>
    </c:if>
    <h4 class="tit-sm">备注信息
        <select class="dggui-select" id="note_phase">
            <option value="">全部</option>
            <c:forEach var="allRemarksNode" items="${allRemarksNodeList}">
                <option value="${allRemarksNode.id}">${allRemarksNode.name}</option>
            </c:forEach>
        </select>
    </h4>
    <div class="table-warp">
        <table class="dggui-table cell-border" id="order_history_table"></table>
    </div>
<%--</div>--%>
<script>
    var orderHistory;
    dggui.use(['table'], function (){
        var table = dggui.table;
        var opt={
            "elem":"#order_history_table",
            "ajax": sysInfo.basePath+"/order_detail/get_history.do",
            "scrollX": "true",//是否开启横项滚动
            "paging": "true",
            /*"fixedColumns": {//锁定列，只有开启scrollX时才生效
                "leftColumns": 4,//左侧锁定2列
                "rightColumns": 1//右侧锁定1列
            },*/
            "fnServerParams": function (aoData) {
                //搜索条件
                aoData = $.extend(aoData, {
                        scProductOrderId:$("#orderId").val(),
                        optstate:$("#note_phase").val()
                    }
                )
                return aoData;
            },
            "aoColumns": [{
                'title': '操作',
                "data" : "nodeName",
                "orderable": false,
                "render": function(data, type, full, meta) {
                    return data;
                }
            },
                {
                    'title': '操作人',
                    'data': "createrName",
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        return data;
                    }
                },
                {
                    "title": "操作人部门",
                    "orderable": false,
                    "data": "createrOrgName",
                    "render": function (data, type, full, meta) {
                        return data;
                    }
                },
                {
                    'title': '操作时间',
                    'data': "createTime",
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        return data;
                    }
                }, {
                    'title': '操作内容',
                    'data': "remark",
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        var str = "";
                        if(row.remarksType==6){
                            str = "申请退单："
                        }
                        if(row.remarksType==11){
                            str = "申请废单："
                        }
                        data = data == null ? "":str + data;
                        var htm = "<span style='overflow: hidden;text-overflow:ellipsis;white-space: nowrap;max-width: 1000px;display: block' title='"+data+"'>"+data+"</span>"
                        return htm;
                    }
                }
            ],
            "columnDefs": []
        };
        orderHistory=table.render(opt);
        $('#note_phase').change(function (){
            orderHistory.ajax.reload();
        });

        // 处理dataTable 异常错误信息
     /*   $.fn.dataTable.ext.errMode = 'none';//不抛出异常
        datatable.on( 'error.dt', function ( e, settings, techNote, message ) {
            dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
        });*/
    });



    function saveremarkByDetail() {
        var productOrderId = $('#orderId').val();
        var nodeId = $('#note_type').val();
        var nodeName = $('#note_type').find("option:selected").text();
        var remark = $('#note_detail').val();
        if(!verifyEmpty($('#note_type'),"请选择备注节点！"))
            return false;
        if(!verifyEmpty($('#note_detail'),"备注信息不能为空！"))
            return false;
        dggui.dialog.confire("确定保存备注吗？", "生产备注", function () {
            dggui.dialog.loading();
            $.ajax({
                type: 'POST',
                data: {
                    nodeId: nodeId,
                    nodeName: nodeName,
                    remark: remark,
                    productOrderId: productOrderId
                },
                url: sysInfo.basePath + '/order_detail/save_product_operating_by_detail.do',
                dataType: 'JSON',
                success: function (data) {
                    dggui.dialog.loading('close');
                    if (data.code != 0) {
                        dggui.dialog.errors(data.msg);
                    } else {
                        dggui.dialog.succeed("操作成功!");
                        $('#note_detail').val('');
                        orderHistory.ajax.reload();
                    }
                },
                error: function () {
                    dggui.dialog.errors('保存失败，请联系管理员！');
                }
            })
        })
    }
</script>